<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 获取一个N到M的随机数
        function getRandom(N, M) {
            return Math.floor(Math.random() * (M - N + 1) + N);
        }
        let random = getRandom(1, 10);

        while (true) {
            let guess = +prompt('请输入一个1到10的数字');
            if (guess < random) {
                alert('猜小了!');
            }
            else if (guess > random) {
                alert('猜大了');
            }
            else {
                alert("猜对了!");
                break;
            }
        }
    </script>
</body>

</html>